package com.lysb.core.entity;

import java.util.List;

/**
 * @author weigu
 */
public class ResponseEntity {
    /**
     * success : true
     * msg : 成功
     * code : 1
     */

    private boolean success;
    private String message;
    private String code;
    private Object data;

    public ResponseEntity() {
    }

    public ResponseEntity(boolean success, String message, String code, Object data) {
        this.success = success;
        this.message = message;
        this.code = code;
        this.data = data;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public static ResponseEntity success(Object data){
        if (data == null) {
            return new ResponseEntity(true, "无相关信息", "1", null);
        }
        if (data instanceof List){
            if (((List) data).size() == 0){
                return new ResponseEntity(true, "无相关信息", "1", null);
            }
        }
        return new ResponseEntity(true, "请求成功", "1", data);
    }

    public static ResponseEntity error(){
        return new ResponseEntity(false, "系统异常", "0", null);
    }

    public static ResponseEntity error(String msg){
        return new ResponseEntity(false, msg, "0", null);
    }
    public static ResponseEntity NO_DATA_FOUND(){
        return new ResponseEntity(false, "医院未查询到数据", "400300", null);
    }

    public static ResponseEntity PROCESS_ERROR(){
        return new ResponseEntity(false, "医院端返回处理错误", "400202", null);
    }
}
